import javax.swing.*;
import java.net.URLClassLoader;
public class ShowGame
{
	/**
	 * Valid arguments: player1_logic player2_logic cols  rows
	 * using the name "human" in one of the logics will activate the default human agent
	 * standard values for cols and rows is 7x6
	 */
	public static void main(String[] arg)
	{
		arg = new String[2];
		arg[0] = "GameLogic";
		arg[1] = "human";
		
		IGameLogic player1;
		IGameLogic player2;
		int cols=4;
		int rows=3;
		try {
			if (!arg[0].equals("human")){
				player1 = (IGameLogic)Class.forName(arg[0]).getConstructor().newInstance();
				player1.initializeGame(cols,rows,1);
			}
			else
				player1=null;
			if (!arg[1].equals("human")){		
				player2 = (IGameLogic)Class.forName(arg[1]).getConstructor().newInstance();
				player2.initializeGame(cols,rows,2);
			}
			else
				player2=null;
			if (player1==null && player2==null)
				throw new Exception("You cannot have two human players, go buy the game!");
			if (arg.length==4){
				cols=Integer.parseInt(arg[2]);
				rows=Integer.parseInt(arg[3]);
			}	   

			FourConnectGUI g = new FourConnectGUI(player1,player2,cols,rows);

			// Setup of the frame containing the game
			JFrame f = new JFrame();
			f.setSize(1000,800);
			f.setTitle("Four Connect");
			f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
			f.getContentPane().add(g);    
			f.setVisible(true);
		}
		catch(ClassNotFoundException ce){
			System.out.println("The player .class file was not found");	    
		}
		catch(NumberFormatException fe){
			System.out.println("You passed invaid values for columns and rows.");
		}
		catch(Exception e){
			System.out.println("There has been an error in the implementation of your IGameLogic");
		}
	}
}
